package org.bspv.pharma.manager.impl;

import java.util.List;

import org.bspv.pharma.dao.RoleDAO;
import org.bspv.pharma.manager.RoleManager;
import org.bspv.pharma.model.security.Role;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * 
 * @author guillaume
 * 
 */
@Service(value = "roleManager")
public class RoleManagerImpl extends AbstractManagerImpl<Role, Long> implements
		RoleManager {

	@Autowired
	public RoleManagerImpl(RoleDAO dao) {
		super(dao);
	}

	/**
	 * {@inheritDoc}
	 */
	public List<Role> getRoles(Role role) {
		return dao.findAll();
	}

	/**
	 * {@inheritDoc}
	 */
	public Role getRole(String rolename) {
		return dao.findUniqueResultBy("name", rolename);
	}

	// /**
	// * {@inheritDoc}
	// */
	// public Long saveRole(Role role) {
	// return dao.save(role);
	// }

	/**
	 * {@inheritDoc}
	 */
	public void removeRole(String rolename) {
		Role r = getRole(rolename);
		dao.delete(r);
	}

}